<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>组件评价</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/layui.css"  media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/toastr.min.css"  media="all">
	<style type="text/css">
		.layui-form-item {
			display: inline-block;
			width: 30%;
		}
		/* .layui-table-cell {
			overflow:visible;
		} */
		thead .layui-table-cell{
		   	height:auto;
		  	overflow:visible;
		  	text-overflow:inherit;
		 	white-space:normal;
		 	text-align: center;
		}
		#details form .layui-input {
			border-top:none;
			border-left:none;
			border-right:none;
			border-bottom:1px solid #AAA !important;
			background-color: rgb(242,242,242);
			border-radius:0;
		}
	</style>
</head>
<body>
<div style="background-color: #0997F7">
	<h2 style="color:#FFF">工位：组件评价工位</h2>
</div>
<div class="" style="margin:10px 0 0 15px;width: 98%">
	<div class="layui-inline">
		<label style="padding:9px 9px;float:left">产品条码：</label><input class="layui-input" id="evCode" style="width: 200px" placeholder="请扫描产品条码" lay-verify="">
	</div>
	<div class="layui-inline">
		<label style="padding:9px 9px;float:left">设备编号：</label><input class="layui-input" id="facilityNumber" style="width: 200px" placeholder="请填写设备编号" lay-verify="">
	</div>
	<button class="layui-btn layui-btn-blue layui-hide" style="margin: 0 0 0 10px" id="reload" data-type="reload"><i class="layui-icon layui-icon-search">  搜索</i></button>
    <input class="layui-btn layui-btn-blue" type="button" style="padding: 0 30px;float:right"" onclick = "checkTodayLog()" value="查看今日工作记录">
</div>
<!-- <div>
	<h2 style="text-align: center;color:#666">组件评价记录</h2>
	<table class="layui-hide" id="evaluate" lay-filter=""evaluate""></table>
</div> -->
<!-- 疑似不良品信息 及操作 -->
<div id="details" style="margin:10px 0 0 15px;background-color:rgb(242,242,242);border-top:#e6e6e6 1px solid">
    <div>
	    <input class="layui-hide" readonly id="remark01"/>
	    <input class="layui-hide" readonly id="remark02"/>
	    <input class="layui-hide" readonly id="remark04"/>
    	<table class="layui-table">
    		<thead>
    			<tr>
    				<th colspan="4"><h2 style="text-align: center;">订单信息</h2></th>
    			</tr>
    		</thead>
    		<tbody>
    			<tr>
    				<td width="20%">产品名称</td>
    				<td><input class="layui-input" readonly id="ptName"/></td>
    				<td width="20%">产品规格</td>
    				<td><input class="layui-input" readonly id="ptStandard"/></td>
    			</tr>
    			<tr>
    				<td width="20%">报检单号</td>
    				<td><input class="layui-input" readonly id="piNumber"/></td>
    				<td width="20%">质检单号</td>
    				<td><input class="layui-input" readonly id="number"/></td>
    			</tr>
    			<tr>
    				<td width="20%">报检人</td>
    				<td><input class="layui-input" readonly id="piPerson"/></td>
    				<td width="20%">报检日期</td>
    				<td><input class="layui-input" readonly id="piDate"/></td>
    			</tr>
    		</tbody>
    	</table>
    	<table class="layui-table">
    		<thead>
    			<tr>
    				<th colspan="4"><h2 style="text-align: center;">组件评价</h2></th>
    			</tr>
    		</thead>
    		<tbody>
    			<tr>
    				<td width="20%">运行水温（℃）</td>
    				<td><input class="layui-input" onFocus="this.value=''"  value= "0" type="number" step="0.01" id="yxsw"/></td>
    				<td width="20%">进水压力（MPa）</td>
    				<td><input class="layui-input" onFocus="this.value=''"  value= "0" type="number" step="0.01" id="jsyl"/></td>
    			</tr>
    			<tr>
    				<td width="20%">产水压力（MPa）</td>
    				<td><input class="layui-input" onFocus="this.value=''"  value= "0" type="number" step="0.01" id="csyl"/></td>
    				<td width="20%">浓水压力（MPa）</td>
    				<td><input class="layui-input" onFocus="this.value=''"  value= "0" type="number" step="0.01" id="nsyl"/></td>
    			</tr>
    			<tr>
    				<td width="20%">产水通量（T/h）</td>
    				<td><input class="layui-input" onFocus="this.value=''"  value= "0" type="number" step="0.01" id="cstl"/></td>
    				<td width="20%">浓水通量（T/h）</td>
    				<td><input class="layui-input" onFocus="this.value=''"  value= "0" type="number" step="0.01" id="nstl"/></td>
    			</tr>
    			<tr>
    				<td width="20%">产水通量【合格】</td>
    				<td><input class="layui-input" readonly value= "${zcEvaluateCriterionEntity.csFluxOne }"/></td>
    				<td width="20%">产水通量【异常】</td>
    				<td><input class="layui-input" readonly value= "${zcEvaluateCriterionEntity.csFluxTwo }"/></td>
    			</tr>
    			<tr>
    				<td width="20%">运行时间（h）</td>
    				<td><input class="layui-input" onFocus="this.value=''"  value= "0" type="number" step="0.01" id="yxTime"/></td>
    				<td width="20%">检测结果</td>
    				<td>
						<!-- <select class="layui-select" id="evResult">
			   				<option value="合格">合格</option>
			   				<option value="降级">降级</option>
			   				<option value="异常处理">异常处理</option>
		   				</select>	 -->
		   				<input class="layui-input" id="evResult" onclick="isPass()" readonly value="">	
					</td>
    			</tr>
    		</tbody>
    	</table>
    	<input style="color:red" class="layui-input" value="* 注：组件的产水通量大于等于【合格】则组件合格，小于等于【异常】则组件异常，否则降级"/>
    	<input id="testTime" hidden/>
    	<div class="layui-form-item">
	   		<div class="" style="margin:10px 0 0 10px">
		  		<input class="layui-btn layui-btn-blue" type="button" style="padding: 0 30px" onclick = "save()" id="firstBtn" value="提交">
		  		<input class="layui-btn layui-btn-blue" type="button" style="padding: 0 30px" onclick = "logout()" value="注销">
			</div>
		</div>
    </div>
</div>
<script src="${pageContext.request.contextPath }/assets/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/layui.all.js"></script>
<script src="${pageContext.request.contextPath }/assets/js/jquery.min.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/toastr.min.js" charset="utf-8"></script>
<script type="text/javascript">
//进入页面，焦点放在条码框
window.onload = function(){
	var oInput = document.getElementById("evCode");
	oInput.focus();
}
//判定是否合格
function isPass(){
	$.ajax({
   	 url:'${pageContext.request.contextPath }/criterion/selectEvaluateCriterion.do'
			,type:'post'
			,dataType:'json'
			,success:function(data){
				var cstl = $("#cstl").val();
				if(cstl>=data.csFluxOne){
					$("#evResult").val("合格")
				}else if(cstl<=data.csFluxTwo){
					$("#evResult").val("异常处理")
				}else{
					$("#evResult").val("降级")
				}
				
			}
    })
}
//查看今日工作量
function checkTodayLog(){
	layer.open({
        type: 1 					//Page层类型
        ,area: ['95%', '600px']   //宽  高
        ,title: '今日组件评价记录'
        ,shade: 0.6 				//遮罩透明度
        ,maxmin: true			    //允许全屏最小化
        ,anim: 1 					//0-6的动画形式，-1不开启
        /* ,content: $("#lookupTable2") */
        ,content: '<table class="layui-hide" id="todayLog" lay-filter="todayLog"></table>'
        ,success:function(){
            layui.use(['table'], function(){
                var table = layui.table;
                table.render({
                    elem: '#todayLog'
                    ,url:'${pageContext.request.contextPath }/evaluate/selectTodayLogList.do'
                    ,title: '今日组件评价记录'
                    ,limits:[10,20,30]
                    ,cols: [[
                        {field:'', title:'序号', sort: true, type:'numbers', width: 60}
                        ,{field:'number', title:'质检单号'}
                        ,{field:'evCode', title:'产品条码'}
                        ,{field:'facilityNumber', title:'设备编号'}
                        ,{field:'yxsw', title:'运行水温'}
                        ,{field:'jsyl', title:'进水压力'}
                        ,{field:'csyl', title:'产水压力'}
                        ,{field:'nsyl', title:'浓水压力'}
                        ,{field:'cstl', title:'产水通量'}
                        ,{field:'nstl', title:'浓水通量'}
                        ,{field:'yxTime', title:'运行时间'}
                        ,{field:'evResult', title:'检测结果'}
                        ,{field:'testPerson', title:'检验人'}
                        ,{field:'testTime', title:'检验时间',width:150,templet :function (row){
                            	return date2String(row.testTime);
                        	}   
                        }
                    ]]
                    ,page: true
                });
            });
        }
	})
}
//注销
function logout(){   
	  window.location.href="${pageContext.request.contextPath }/logout.do";
 }
//日期格式转换
function date2String(timestamp){
	var d = new Date(timestamp);
	var date = (d.getFullYear()) + "-" + 
       (d.getMonth() + 1<10?"0"+(d.getMonth() + 1):d.getMonth() + 1) + "-" +
       (d.getDate()<10?"0"+d.getDate():d.getDate()) + " " + 
       (d.getHours()<10?"0"+d.getHours():d.getHours()) + ":" + 
       (d.getMinutes()<10?"0"+d.getMinutes():d.getMinutes()) + ":" + 
       (d.getSeconds()<10?"0"+d.getSeconds():d.getSeconds());
       
       return date;
}
/* layui.use(['table','layer','upload','form'], function(){
	var table = layui.table;
	var layer = layui.layer,
    form = layui.form;
	
	var $ = layui.jquery, active = {
			reload:function () {
				var productCode = $("#evCode").val();
				table.reload('contenttable',{
					method:'get',
					where:{productCode:productCode}
					,page: {
						curr: 1 //重新从第 1 页开始
					}
				});
			}
		}
	$('.layui-btn').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
     table.render({
 	    elem: '#evaluate'
 	    ,url:'${pageContext.request.contextPath }/productTracing/selectEvaluateInfoByCode.do'
 	    ,title: '评价记录'
 	    ,id :'contenttable'
 	    ,limits:[10,20,30]
 	    ,cols: [[
 			   {field:'', title:'序号', sort: true, type:'numbers', width: 60}
 			   ,{field:'yxsw', title:'运行水温℃'}
		      ,{field:'jsyl', title:'进水压力MPa'}
		      ,{field:'csyl', title:'产水压力MPa'}
		      ,{field:'nsyl', title:'浓水压力MPa'}
		      ,{field:'cstl', title:'产水通量T/h'}
		      ,{field:'nstl', title:'浓水通量T/h'}
		      ,{field:'yxTime', title:'运行时间h'}
		      ,{field:'evResult', title:'检测结果'}
		      ,{field:'testTime', title:'日期'}
 		    ]]
 	    ,done:function(data){
 	    	var index = data.data.length-1;
 	    	if(data.count!='0'){
 	    		$("#firstBtn").attr("disabled",true);
 	    		$("#firstBtn").css("background","#AAA");
 	    	}
 	    }
 	    ,page: true
 	});
}) */
function keyDown(e){
    //IE内核浏览器  
     if (navigator.appName == 'Microsoft Internet Explorer'){
           var keycode = event.keyCode;  
           var realkey = String.fromCharCode(event.keyCode);  
     }else {//非IE内核浏览器  
           var keycode = e.which;  
           var realkey = String.fromCharCode(e.which);  
     }  
   // console.log('按键码:' + keycode +  '字符: ' + realkey);  

   //监听Enter键  
   if(keycode==13){  
	    var d = new Date();
	    var date = (d.getFullYear()) + "-" + 
           (d.getMonth() + 1<10?"0"+(d.getMonth() + 1):d.getMonth() + 1) + "-" +
           (d.getDate()<10?"0"+d.getDate():d.getDate()) + " " + 
           (d.getHours()<10?"0"+d.getHours():d.getHours()) + ":" + 
           (d.getMinutes()<10?"0"+d.getMinutes():d.getMinutes()) + ":" + 
           (d.getSeconds()<10?"0"+d.getSeconds():d.getSeconds());
           $("#testTime").val(date);
         var code = $("#evCode").val();
         $.ajax({
        	 url:'${pageContext.request.contextPath }/numbered/selectProductTest.do'
 				,type:'post'
 				,data:{"code":code}
 				,dataType:'json'
 				,success:function(data){
 					if(data == 0){
 						toastr.warning("未找到订单！");
 						setTimeout(function(){  //使用  setTimeout（）方法设定定时500毫秒
 							window.location.reload();  
 						},500);
 					}else{
 						$.ajax({
 							url:'${pageContext.request.contextPath }/productTracing/selectLeakHuntingInfoByCode.do'
							,type:'post'
			 				,data:{"productCode":code}
			 				,dataType:'json'
			 				,success:function(data1){
			 					if(data1.count<=0){
			 						toastr.warning("请先进行检漏操作！");
			 						setTimeout(function(){  //使用  setTimeout（）方法设定定时500毫秒
			 							window.location.reload();  
			 						},500);
			 					}
			 				}
 						})
 						$("#reload").click();
 						$("#ptName").val(data.ptName);
 	 					$("#ptStandard").val(data.ptStandard);
 	 					$("#piNumber").val(data.piNumber);
 	 					$("#number").val(data.number);
 	 					$("#piPerson").val(data.piPerson);
 	 					$("#piDate").val(date2String(data.piDate));
 	 					$("#remark01").val(data.remark01);
 	 					$("#remark02").val(data.remark02);
 	 					$("#remark04").val(data.remark04);
 	 					 $.ajax({
 	 			        	 url:'${pageContext.request.contextPath }/productTracing/selectEvaluateInfoByCode.do'
 	 			        	,type:'post'
 	 			      		,data:{"productCode":code}
 	 			      		,dataType:'json'
 	 			      		,success:function(data){
 	 			      			var index = data.data.length-1;
 	 			     	    	if(data.count!='0'){
 	 			     	    		$("#firstBtn").attr("disabled",true);
 	 			     	    		$("#firstBtn").css("background","#AAA");
 	 			     	    		toastr.warning("已完成组件评价！");
 	 			     	    	}else{
 	 								$("#firstBtn").attr("disabled",false);
 	 				     	    	$("#firstBtn").css("background","#009688");
 	 							}
 	 			      		}
 	 			         })
 					}
 				}
         })
        
   }  
   
}  
//按键事件
document.onkeydown=keyDown;
//保存处置结果
function save(){
	$("#firstBtn").attr("disabled",true);
	var evCode = $("#evCode").val();
	var evResult = $("#evResult").val();
	if(evCode==""){
		toastr.warning("请先扫描条形码！");
		setTimeout(function(){  //使用  setTimeout（）方法设定定时500毫秒
			window.location.reload();  
		},1000);
	}else{
		var number = $("#number").val();
		var facilityNumber = $("#facilityNumber").val();
		var ptName = $("#ptName").val();
		var ptStandard = $("#ptStandard").val();
		var yxsw = parseFloat($("#yxsw").val()==""?0:$("#yxsw").val());
		var jsyl = $("#jsyl").val()==""?0:$("#jsyl").val();
		var csyl = $("#csyl").val()==""?0:$("#csyl").val();
		var nsyl = $("#nsyl").val()==""?0:$("#nsyl").val();
		var cstl = $("#cstl").val()==""?0:$("#cstl").val();
		var nstl = $("#nstl").val()==""?0:$("#nstl").val();
		var yxTime = $("#yxTime").val()==""?0:$("#yxTime").val();
		var testTime = $("#testTime").val();
		var tInsPerson = $("#piPerson").val();
		var tInsDate = $("#piDate").val();
		var tStation = "组件评价工位";
		if(facilityNumber==""){
			toastr.warning("请输入设备编号！");
			$("#firstBtn").attr("disabled",false);
		}else if(evResult==""){
			toastr.warning("请选择检验结果！");
			$("#firstBtn").attr("disabled",false);
		}else{
			$.ajax({
				type:'post'
				,url:'${pageContext.request.contextPath }/evaluate/insertEvaluate.do'
				,data:{number:number,evCode:evCode,facilityNumber:facilityNumber,yxsw:yxsw,jsyl:jsyl,csyl:csyl,nsyl:nsyl,cstl:cstl,nstl:nstl,yxTime:yxTime,evResult:evResult,testTime:testTime}
				,dataType:'json'
				,success:function(res){
					if(res>0){
						if(evResult=="异常处理"){
							//异常判定推送到不合格处置
							$.ajax({
								type:'post'
								,url:'${pageContext.request.contextPath }/leakHunting/insertProductToTest.do'
								,data:{tNumber:number,tCode:evCode,tName:ptName,tStandard:ptStandard,tWay:evResult,tStatus:"0",tTestDate:testTime,tInsPerson:tInsPerson,tInsDate:tInsDate,tStation:tStation}
								,dataType:'json'
							})
						}else{
							var remark01 = $('#remark01').val();
							var remark02 = $("#remark02").val();
							var remark04 = $("#remark04").val();
							//减库存
							$.ajax({
								type:'post'
								,url:'${pageContext.request.contextPath }/lineSideLibrary/lineSideLibraryOut.do?pnum='+remark01+'&&quantity=1&&productionOrder='+remark02+'&&team='+remark04+'&&type=1&&positionName=评价'
								,dataType:'json'
								,success:function(res){
									
								}
							})
						}
						toastr.success("提交成功！");
						setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
							window.location.reload();  
						},2000);
					}else{
						toastr.error("提交失败！");
					}
				}
			})
		}
	}
	
}
toastr.options.positionClass = 'toast-top-center'; //提示框的位置设置为中上
</script>
</body>
</html>